package com.myway.service.ibe.command;

import com.travelsky.ibe.client.pnr.DETR;
import com.travelsky.ibe.client.pnr.DETRResult;
import com.travelsky.ibe.client.pnr.DETRSegment;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * Created by Administrator on 2018/1/19.
 * 获取客票状态
 */
public class DETRCommand extends BaseIBECommand {
    public void execute(Map<String, Object> map) {

    }

    public String  getBaggage(String ticketNo,int num){
        if(StringUtils.isEmpty(ticketNo)){
            return "";
        }
        try{
            DETR detr=new DETR();
            this.configIBEClient(detr, "MJ");
            DETRResult result = detr.getScheduleByTktNo(ticketNo);
            if(result == null) return "";
            DETRSegment segment = result.getSegment(num);
            if(segment==null) return "";
            boolean fpc = segment.isFPC();
            int baggage=0;
            if(fpc){
                 baggage = segment.getBaggagePiece();
            }else{
                 baggage = segment.getBaggageWeight();
            }
            String baggageWeightUnit = segment.getBaggageWeightUnit();
            return baggage+baggageWeightUnit;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }

}
